//
//  HQEditPasswordViewController.m
//  MobileiOS
//
//  Created by 郝庆松 on 2018/5/5.
//  Copyright © 2018年 PCITC. All rights reserved.
//

#import "HQEditPasswordViewController.h"
#import "AppDelegate.h"
#import "HQNetWork.h"
@interface HQEditPasswordViewController ()

@end

@implementation HQEditPasswordViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"修改密码";
    self.navigationItem.rightBarButtonItem = [UIBarButtonItem barButtonItemTitle:@"确认修改" withTitleColor:[self colorHexValue:0x98A4B3] withFont:15 withTarget:self withSelector:@selector(contentEdit)];
}

/**
 确认修改密码
 */
-(void)contentEdit{
    if([self isInputEmpty:_oldPassword.text]){
        [self tostView:@"请输入原密码"];
        return;
    }
    if([self isInputEmpty:_newPassword.text]){
        [self tostView:@"请输入新密码"];
        return;
    }
    if([self isInputEmpty:_contentPassword.text]){
        [self tostView:@"请重复新密码"];
        return;
    }
    if(![_newPassword.text isEqualToString:_contentPassword.text]){
        [self tostView:@"两次输入密码不一致"];
        return;
    }
    [self showHudText:@"修改中..."];
    NSDictionary *dict =@{
                          @"uid":[UserModelManager userID],
                          @"password":_oldPassword.text,
                          @"s_password":_newPassword.text
                          };
    [HQNetWork requetParam:dict withMethod:[HQMethod savePass] suc:^(NSDictionary *sucData) {
        [self hiddnHud];
        if([sucData[kStatus]integerValue] == 1){
            [self tostView:@"密码修改成功"];
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                [UserModelManager logOut];
                [(AppDelegate *)[UIApplication sharedApplication].delegate showLogin];
            });
        }else{
            [self tostView:sucData[kInfo]];
        }
    } fail:^{
        [self hiddenErrorHud];
    }];
}

@end
